#include "ecclient_test_pch.h"
#include "../eccommon/network.h"
#include "../eccommon/data.h"

using namespace std;
using namespace ec;
using namespace ec::TestData;
using namespace ec::SerializationServer;

static const unsigned short SERVER_PORT = 61978;

void OnDataRecieved(std::vector<Person> &people)
{
	if(people.empty())
	{
		cout << "Error: No people received" << endl;
		return;
	}

	for (auto &person : people)
	{
		cout << "Received person:" << endl <<
			"Name: " << person.Name << endl <<
			"Age: " << person.Age << endl <<
			"Height: " << person.HeightInInches << " inches" << endl << endl;
	}
}

int main(int argc, char* argv[])
{
	////wait 1 second before starting
	//boost::this_thread::sleep(boost::posix_time::seconds(1));
	
	boost::asio::io_service ioService;
	Client<Person>::OnDataReceivedFunction func(&OnDataRecieved);
	Client<Person> client(ioService, "localhost", to_string(SERVER_PORT), func);
	ioService.run();

	cout << "Client completed. Press any key to exit." << endl;
	getc(stdin);

	return 0;
}

